package tech.summerly.weather.component.activities

import android.os.Bundle
import android.preference.PreferenceFragment
import android.support.v7.app.AppCompatActivity
import org.jetbrains.anko.defaultSharedPreferences
import tech.summerly.weather.AppContext
import tech.summerly.weather.R
import tech.summerly.weather.util.string

class SettingsActivity : AppCompatActivity() {

    companion object {

        private val preference get() = AppContext.instance.defaultSharedPreferences

        private const val TYPE_CURVE = "type_curve"

        fun isChartLineSmooth(): Boolean {
            return when (preference.getString(string(R.string.key_chart_line), TYPE_CURVE)) {
                TYPE_CURVE -> true
                else -> false
            }
        }

        fun isShowLifeStyle(): Boolean {
            return preference.getBoolean(string(R.string.key_life_style), true)
        }

        fun getPushUrl(): String {
            return preference.getString(string(R.string.key_setting_push_url), "rtmp://10.42.0.1/weather/dl")
        }

    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.title = getString(R.string.setting)
        fragmentManager.beginTransaction()
                .replace(android.R.id.content, MyPreferenceFragment())
                .commit()
    }


    class MyPreferenceFragment : PreferenceFragment() {

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            addPreferencesFromResource(R.xml.pref_settings)
        }
    }
}
